import threading
import _thread
# import pdb
import time
def thread_func(i,**kwargs):
    #pdb.set_trace()#断点（pdb执行断点操作，输入c退出回车，输入n继续-------ide断点不能操作的时候）
    time.sleep(2)
    # 拿取当前线程
    # print(threading.currentThread())
    print("子线程执行")
    # print(*args)
    print(i)

threads = []
for i in range(8):
    thread = threading.Thread(target=thread_func,args=(i,),kwargs={"name":"yanghan"})
    thread.start()
    threads.append(thread)
    # 获取id
    # print(thread.ident)
for thread in threads:
    thread.join()
    #通过阻塞使用alive判断线程是否活着
    #thread.join(2)
    # if thread.isAlive():
    #     print("the ch is alive now")
print("主线程结束")



# 不建议使用start_new_thread方法创建线程（需要使用while True执行子线程）
# import _thread
# import time
#
# def work_thread(id):
#
#     cnt = 1
#
#     print ("Thread %d is runing..." % id)
#
#     while True:
#         print( "Thread with ID %d has counter value %d" % (id, cnt))
#         time.sleep(2)
#         cnt += 1
#
#
# for i in range(1,5):
#     _thread.start_new_thread(work_thread,(i,))
#
# print( "Main thread doing an infinite wait loop...")
#
# while True:
#     pass
